package br.edu.unibratec.aula27;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class MeuOverlay extends Overlay {

	private GeoPoint coordenada;
	private Bitmap img;
	
	public MeuOverlay(Context ctx) {
		img = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ponto);
	}
	
	public void setCoordenada(GeoPoint gp){
		coordenada = gp;
	}
	
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		super.draw(canvas, mapView, shadow);
		
		if (coordenada != null){
			Projection prj = mapView.getProjection();
			Point ponto = prj.toPixels(coordenada, null);
			
			canvas.drawBitmap(img, ponto.x, ponto.y, null);
		}
	}
	
	@Override
	public boolean onTap(GeoPoint p, MapView mapView) {
		Toast.makeText(mapView.getContext(), "Teste", Toast.LENGTH_SHORT).show();
		return super.onTap(p, mapView);
	}
}
